package com.jingdianjichi.subject.domain.Handler.subject;

import com.jingdianjichi.subject.common.enums.IsDeletedCodeEnum;
import com.jingdianjichi.subject.common.enums.SubjectInfoTypeCodeEnum;

import com.jingdianjichi.subject.domain.entity.SubjectInfoBo;

import com.jingdianjichi.subject.infra.basic.entity.SubjectRadio;
import com.jingdianjichi.subject.infra.basic.service.SubjectInfoService;
import com.jingdianjichi.subject.infra.basic.service.SubjectRadioService;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.LinkedList;
import java.util.List;

@Component
public class RadioTypeHandler implements SubjectTypeHandler {



    @Resource
    SubjectRadioService subjectRadioService;

    @Override
    public SubjectInfoTypeCodeEnum getHandlerType() {
        return SubjectInfoTypeCodeEnum.RADIO;
    }

    @Override
    public void add(SubjectInfoBo subjectInfoBo) {
        List<SubjectRadio> subjectRadioList = new LinkedList<>();


        subjectInfoBo.getOptionList().forEach(subjectAnswerBo -> {
            SubjectRadio subjectRadio = new SubjectRadio();
            BeanUtils.copyProperties(subjectAnswerBo, subjectRadio);
            subjectRadio.setSubjectId(subjectInfoBo.getId());
            subjectRadio.setIsDeleted(IsDeletedCodeEnum.UN_DELETED.getCode());
            subjectRadioList.add(subjectRadio);
            subjectRadioService.batchInsert(subjectRadioList);
        });





    }
}
